package com.mapper;

import com.pojo.Product;
import lombok.Data;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {
    @Select("SELECT * FROM PRODUCT")
    List<Product> findAll();

    @Select("SELECT * FROM PRODUCT WHERE id=#{id}")
    Product findById(Long id);

    @Insert("INSERT INTO product(name, description, price, stock, image_url, category_id, status, created_at) " +
            "VALUES(#{name}, #{description}, #{price}, #{stock}, #{imageUrl}, #{categoryId}, #{status}, NOW())")
    void insert(Product product);

    @Select("SELECT * FROM product WHERE category_id = #{categoryId}")
    List<Product> findByCategoryId(Long categoryId);

    @Delete("DELETE FROM product WHERE id = #{id}")
    void delete(Integer id);

    @Update("UPDATE product SET name=#{name}, description=#{description}, price=#{price}, stock=#{stock}, image_url=#{imageUrl}, category_id=#{categoryId}, status=#{status} WHERE id=#{id}")
    void update(Product product);
}
